﻿using System;
using System.Windows;
using System.Windows.Media;
using System.Windows.Shapes;

namespace HexTD.util
{
	public class Geometry
	{
		/* top-middle
		 * top-right
		 * bottom-right
		 * bottom-middle
		 * bottom-left
		 * top-left
		 */

		public static Ellipse createCircle(float x, float y, float r)
		{
#if PORT
			return new Ellipse.Float(x - r, y - r, r * 2, r * 2);
#else
			return new Ellipse();
#endif
		}

		public static float[,] createPolyCoords(float scale, float x, float y)
		{
			float width = (float)Math.Sin(Math.PI / 3) * scale;
			float[,] points = {
				{x+0    , y-scale},
				{x+width, y-scale/2},
				{x+width, y+scale/2},
				{x+0    , y+scale},
				{x-width, y+scale/2},
				{x-width, y-scale/2}};
			return points;
		}

		public static float[,] createPolyCoords(float scale)
		{
			return createPolyCoords(scale, 0, 0);
		}

		public static Polyline coordsToGeneralPath(float[,] points, bool closed)
		{
			Polyline poly = new Polyline();
			for (int index = 1; index < points.GetLength(0); index++)
			{
				poly.Points.Add(new Point(points[index, 0], points[index, 1]));
			};
			if (closed && points.GetLength(0) > 0)
			{
				poly.Points.Add(new Point(points[0, 0], points[0, 1]));
			}
			return poly;
		}
	}
}
